package com.vlin.api.client.request.defaut;

import java.nio.charset.Charset;
import java.util.Map.Entry;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;

import com.vlin.api.client.Method;
import com.vlin.api.client.Params;
import com.vlin.api.client.request.RequestProducer;

public class DefaultedPOSTRequestProducer implements RequestProducer {

	@Override
	public HttpUriRequest produceRequest(String url, Method method, Params params) {
		HttpPost httpPost = new HttpPost(url);
		
		
	
		
		for(Entry<String, String> entry : params.getHeadParams().entrySet()) {
			httpPost.addHeader(entry.getKey(), entry.getValue());
		}
		httpPost.addHeader("Content-Type", "application/json");
		httpPost.setEntity(new StringEntity(params.getParams().get("body"), Charset.forName("UTF-8")));
		return httpPost;
	}

	@Override
	public boolean supportMethod(Method method) {
		
		return getMethod() != null && getMethod().equals(method);
	}

	@Override
	public Method getMethod() {
		
		return Method.POST;
	}

}
